package com.atguigu.singleton.type1;

/**
 * @author ccc
 * @create 2020-07-16 15:11
 */
public class MySingletonTest01 {
    public static void main(String[] args) {
        MySingleton instance = MySingleton.getInstance();
        MySingleton instance2 = MySingleton.getInstance();

        System.out.println(instance.hashCode());
        System.out.println(instance2.hashCode());
    }
}

class MySingleton{
    //1、构造器私有化
    private MySingleton(){}

    //2、内部获取bean

    static {
        instance = new MySingleton();
    }
    private static MySingleton instance;

    //3、提供公共的方法获取
    public static MySingleton getInstance(){
        return instance;
    }
}
